package com.aaa.controller;

import com.aaa.pojos.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @author liuyp
 * @since 2025/4/26
 */
@RestController
public class DemoSessionController {

    @GetMapping("/s1")
    public Result s1(HttpSession session){
        //模拟登录成功之后，将用户的身份信息存储到session对象里
        session.setAttribute("id",1);
        session.setAttribute("username", "tom");
        System.out.println("s1执行了");
        return Result.success();
    }

    @GetMapping("/s2")
    public Result s2(HttpSession session){
        Object id = session.getAttribute("id");
        Object username = session.getAttribute("username");
        System.out.println("id = " + id + ",  username = " + username);

        return Result.success();
    }
}
